/**
 * 
 */
package com.elephantgreen.xml;

import java.io.File;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;

import com.elephantgreen.common.ElephantgreenCommon;

/**
 * @author ABC
 * 
 */
@SuppressWarnings("serial")
public class CreateXmlFile extends ElephantgreenCommon {

	private String xmlFileName;
	private Document document;

	/**
	 * 
	 */
	@SuppressWarnings("unused")
	private CreateXmlFile() {


	}

	/**
	 * @param xmlFileName
	 * @param element
	 */
	public CreateXmlFile(String xmlFile, Document doc) {

		xmlFileName = xmlFile;
		document = doc;

		try {

			// write the content into xml file
			TransformerFactory transformerFactory = TransformerFactory
					.newInstance();
			Transformer transformer = transformerFactory.newTransformer();
			DOMSource source = new DOMSource(document);
			StreamResult result = new StreamResult(new File(xmlFileName
					+ ".xml"));

			transformer.transform(source, result);

		} catch (TransformerConfigurationException tce) {
			tce.printStackTrace();
		} catch (TransformerException te) {

			te.printStackTrace();
		}
	}

	public String getXmlFileName() {
		return xmlFileName;
	}

	public void setXmlFileName(String xmlFileName) {
		this.xmlFileName = xmlFileName;
	}

	public Document getDocument() {
		return document;
	}

	public void setDocument(Document document) {
		this.document = document;
	}

}
